package com.mlf.factory.factory.spring;

import com.mlf.factory.easyFactory.demo.Shape;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

// 3. 客户端使用
@Service
public class ShapeService {
   // 直接注入产品（Spring自动调用getObject()）
   @Autowired
   private Shape circle;

   // 获取工厂Bean本身需加&前缀
   @Autowired
   private FactoryBean<Shape> circleFactory;

   public void shapeDraw() {
      System.out.println("circle: " + circle);
       circle.draw();
   }

   public void shapeFactoryDraw() {
      try {
         System.out.println("circleFactory: " + circleFactory);
         circleFactory.getObject().draw();
      } catch (Exception e) {
         throw new RuntimeException(e);
      }
   }
}
